package com.itboye.ihomebank.responsitory;

import com.google.gson.reflect.TypeToken;
import com.itboye.ihomebank.base.BaseNetRepository;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.bean.AdminKeyBean;
import com.itboye.ihomebank.bean.BangDingBean;
import com.itboye.ihomebank.bean.GuanLiPassBean;
import com.itboye.ihomebank.bean.HouseBean;
import com.itboye.ihomebank.bean.KaiSuoJiLu;
import com.itboye.ihomebank.bean.KaiSuoJiLuTwo;
import com.itboye.ihomebank.bean.KeyOfLockBean;
import com.itboye.ihomebank.bean.KeysBean;
import com.itboye.ihomebank.bean.RentInfoBean;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.interfaces.KeyTwoInterface;
import com.itboye.ihomebank.net.BaseErrorListener;
import com.itboye.ihomebank.net.BaseSuccessReqListener;
import com.itboye.ihomebank.net.ByJsonRequest;
import com.itboye.ihomebank.util.SPUtils;
import com.itboye.ihomebank.util.TimesUtils;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 白马锁钥匙接口类
 */
public class KeyTwoRepository  extends BaseNetRepository implements KeyTwoInterface<HouseBean> {
    private String api = "100";
    private String my_key="BY_Sciener2_listUserKey";//我的钥匙（v3）--已改
    private String register = "BY_Sciener2_reg";// 注册		--已改
    private String addmain = "BY_Sciener2_init";//  锁初始化(v3)	--已改
    private String kaisuo = "BY_Sciener2_listRecord";// 开锁记录(v3)	--已改
    private String youxiaoqi = "BY_Sciener2_changePeriod";// 修改钥匙有效期(v3)7	--已改
    private String dongjie = "BY_Sciener2_lockKey";// 冻结钥匙(v3)	--已改
    private String jiedong = "BY_Sciener2_unlockKey";// 解冻钥匙(v3)	--已改
    private String jianpanPass = "BY_Sciener2_resetKeyboardPwd";// 重置键盘密码(v3)  --已改（待检查接口）
    private String sendJianPanPass = "BY_Sciener2_getKeyboardPwd";// 发送键盘密码(v3)	--已改
    private String judge="BY_Sciener2_isRegSitri";//判断白马云锁是否注册
    private String regSitri="BY_Sciener2_regSitri";//注册白马云锁
    private String initSitri="BY_Sciener2_initSitri";//锁初始化-白马锁（绑定到服务器）
    private String rentInfo="BY_Sciener2_getRentInfo";//获取租户信息--发送钥匙的时候用到。当该用户的这把锁绑定了房源，获取到该客户的信息
    private String setPower="BY_Sciener2_setPower";//设置锁电量

    private String uploadJiLu = "BY_Sciener2_unlock";// 上传开锁记录(v3)	--已改
    private String myKey = "BY_Sciener2_listUserKey";// 查询我的钥匙(v3)	--已改
    private String updateKey = "BY_Sciener2_edit";// 修改钥匙名字(v3)	--已改
    private String sendKey = "BY_Sciener2_sendKey";// 发送钥匙(v3)	--已改
    private String keyOfLock = "BY_Sciener2_listKey";// 锁的钥匙列表(v3)	--已改
    private String passJiLu = "BY_Sciener2_listKeyboardLog";//键盘密码记录(v3)	--已改
    private String unbindAdmin = "BY_Sciener2_deleteKey";// 解绑管理员(v3) --已改
    private String tuisong = "BY_Sciener2_ifPush";// 锁推送开关(v3) --已改
    private String qianzhi = "BY_Sciener2_preAddKeyboardPwd";// 密码添加前置
    private String deletePass = "BY_Sciener2_deleteKeyboardPwd";// 密码删除回调
    private String modifyPass = "BY_Sciener2_changeKeyboardPwd";// 密码修改回调
    private String addPass = "BY_Sciener2_addKeyboardPwd";// 密码添加回调
    private String modifyAlias = "BY_Sciener2_editKeyboardPwd";// 密码别名
    private String bieming = "BY_Sciener2_editkey";// 钥匙别名
    public KeyTwoRepository(ICompleteListener iCompleteListener) {
        super(iCompleteListener);
    }
    /**
     * 注册
     */
    @Override
    public void onRegister(String uid) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(register, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();

    }
    /**
     *  锁初始化(v3)
     */
    @Override
    public void onAddMain(String uid, String lock_type, String lockName,
                           String lockAlias, String lockMac, String lockKey,
                           String lockFlagPos, String aesKeyStr, String version,
                           String adminPwd,String noKeyPwd,String deletePwd,String pwdInfo,String timestamp,String specialValue) {
        Type type = new TypeToken<BangDingBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("lock_type", lock_type);
        map.put("lockName", lockName);
        map.put("lockAlias", lockAlias);
        map.put("lockMac", lockMac);
        map.put("lockKey", lockKey);
        map.put("lockFlagPos", lockFlagPos);
        map.put("aesKeyStr", aesKeyStr);
        map.put("lockVersion", version);
        map.put("adminPwd", adminPwd);
        map.put("noKeyPwd", noKeyPwd);
        map.put("deletePwd", deletePwd);
        map.put("pwdInfo", pwdInfo);
        map.put("timestamp", timestamp);
        map.put("specialValue", specialValue);
        (new ByJsonRequest.Builder<BangDingBean>())
                .setTypeVerParamsAndReturnClass(addmain, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<BangDingBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();

    }


    /**
     * 开锁记录
     */
    @Override
    public void onKaiSuoJiLu(String uid, String lock_id, String current_page,
                              String per_page) {
        Type type = new TypeToken<KaiSuoJiLuTwo>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lock_id);
            map.put("current_page", current_page);
            map.put("per_page", per_page);
            map.put("latest", "1");//,1(是)0(d,否)从最近一次初始化开始
            (new ByJsonRequest.Builder<KaiSuoJiLuTwo>(lock))
                    .setTypeVerParamsAndReturnClass(kaisuo, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<KaiSuoJiLuTwo>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lock_id);
            map.put("current_page", current_page);
            map.put("per_page", per_page);
            map.put("latest", "1");//,1(是)0(d,否)从最近一次初始化开始
            (new ByJsonRequest.Builder<KaiSuoJiLuTwo>())
                    .setTypeVerParamsAndReturnClass(kaisuo, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<KaiSuoJiLuTwo>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }


    }
    //修改密码有效期
    @Override
    public void onYouXiaoQi(String uid, String key_id, String lock_id, String start, String end) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lock_id);
            map.put("key_id", key_id);
            map.put("start", start);
            map.put("end", end);
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(youxiaoqi, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lock_id);
            map.put("key_id", key_id);
            map.put("start", start);
            map.put("end", end);
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(youxiaoqi, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }
    /**
     * 冻结钥匙
     */
    @Override
    public void onDongJie(String uid, String to_uid, String lock_id,
                           String key_id) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("to_uid", to_uid);
            map.put("lock_id", lock_id);
            map.put("key_id", key_id);
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(dongjie, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("to_uid", to_uid);
            map.put("lock_id", lock_id);
            map.put("key_id", key_id);
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(dongjie, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }


    }

    /**
     * 解冻钥匙
     */
    @Override
    public void onJieDong(String uid, String to_uid, String lock_id,
                           String key_id) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("to_uid", to_uid);
            map.put("lock_id", lock_id);
            map.put("key_id", key_id);
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(jiedong, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("to_uid", to_uid);
            map.put("lock_id", lock_id);
            map.put("key_id", key_id);
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(jiedong, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }


    }
    /**
     * 重置键盘密码
     */
    @Override
    public void onJianPanPass(String uid, String lock_id, String pwd_info,
                               String timestamp) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lock_id);
            map.put("pwdInfo", pwd_info);
            map.put("timestamp", timestamp);
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(jianpanPass, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lock_id);
            map.put("pwdInfo", pwd_info);
            map.put("timestamp", timestamp);
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(jianpanPass, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }

    /**
     * 发送键盘密码
     */
    @Override
    public void onKeyboardPwd(String uid, String lock_id, String pwd_type,
                               String to_phone, String start, String end, String date) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lock_id);
            map.put("pwd_type", pwd_type);
            map.put("to_phone", to_phone);
            map.put("start", start);
            map.put("end", end);
            map.put("app_time", date);
            map.put("alias", "");
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(sendJianPanPass, apiVer, map,
                            type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();

        }else {
            map.put("uid", uid);
            map.put("lock_id", lock_id);
            map.put("pwd_type", pwd_type);
            map.put("to_phone", to_phone);
            map.put("start", start);
            map.put("end", end);
            map.put("app_time", date);
            map.put("alias", "");
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(sendJianPanPass, apiVer, map,
                            type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();

        }

    }

    /**
     * 判断是否注册白马锁
     */
    @Override
    public void onJudge(String uid) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(judge, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
    /**
     * 注册白马锁
     */
    @Override
    public void regSitri(String uid) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(regSitri, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
    /**
     * 锁初始化-白马锁（绑定到服务器）
     * @param uid
     * @param lockMac
     * @param lockName
     * @param lockAlias
     * @param app_time		时间
     * @param pwdInfo   	SDK返回的锁列表数据
     */
    @Override
    public void initSitri(String uid, String lockMac, String lockName, String lockAlias, String app_time, String pwdInfo) {
        Type type = new TypeToken<BangDingBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("lockMac", lockMac);
        map.put("lockName", lockName);
        map.put("lockAlias", lockAlias);
        map.put("app_time", app_time);
        map.put("pwdInfo", pwdInfo);

        (new ByJsonRequest.Builder<BangDingBean>())
                .setTypeVerParamsAndReturnClass(initSitri, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<BangDingBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
    /**
     * 获取租户信息--发送钥匙的时候用到。当该用户的这把锁绑定了房源，获取到该客户的信息
     */
    @Override
    public void onRentInfo(String uid, String lock_id) {
        Type type = new TypeToken<RentInfoBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lock_id);

            (new ByJsonRequest.Builder<RentInfoBean>(lock))
                    .setTypeVerParamsAndReturnClass(rentInfo, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<RentInfoBean>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lock_id);

            (new ByJsonRequest.Builder<RentInfoBean>())
                    .setTypeVerParamsAndReturnClass(rentInfo, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<RentInfoBean>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }

    @Override
    public void onSetPower(String uid, String lock_id, int power) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("lock_id", lock_id);
        map.put("power", power);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(setPower, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 上传开锁记录
     */
    @Override
    public void onUploadHistoryOfUnlock(String uid, String lockId,String records, String success,int power) {
        // TODO Auto-generated method stub
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lockId);
            map.put("records", records);
            map.put("success", success);
            map.put("power", power);
            map.put("unlock_time", TimesUtils.getStamp());
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(uploadJiLu, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lockId);
            map.put("records", records);
            map.put("success", success);
            map.put("power", power);
            map.put("unlock_time", TimesUtils.getStamp());
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(uploadJiLu, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }
    public void onUploadHistoryOfUnlockTwo(String uid, String lockId,String records, String success,String reset_rent_pass,int power) {
        // TODO Auto-generated method stub
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lockId);
            map.put("records", records);
            map.put("success", success);
            map.put("power", power);
            map.put("reset_rent_pass", reset_rent_pass);
            map.put("unlock_time", TimesUtils.getStamp());
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(uploadJiLu, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lockId);
            map.put("records", records);
            map.put("success", success);
            map.put("power", power);
            map.put("reset_rent_pass", reset_rent_pass);
            map.put("unlock_time", TimesUtils.getStamp());
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(uploadJiLu, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }
    /**
     * 查询我的钥匙
     */
    @Override
    public void onMyKey(String uid,String kword) {
        // TODO Auto-generated method stub
        Type type = new TypeToken<List<KeysBean>>() {
        }.getType();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();

        if (lock){
            map.put("sid", uid);
            map.put("kword", kword);
            (new ByJsonRequest.Builder<List<KeysBean>>(lock))
                    .setTypeVerParamsAndReturnClass(myKey, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<List<KeysBean>>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("kword", kword);
            (new ByJsonRequest.Builder<List<KeysBean>>())
                    .setTypeVerParamsAndReturnClass(myKey, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<List<KeysBean>>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }

    /**
     * 修改钥匙名字
     */
    @Override
    public void onUpdateKey(String uid, String lockId, String alias) {
        // TODO Auto-generated method stub
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("lock_id", lockId);
        map.put("alias", alias);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(updateKey, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
    /**
     * 发送钥匙
     * @param send_type	钥匙类型8.0 说明里面的钥匙类型 管理员发送(1用户/2租户),租户发送(3租户用户)]
     */
    @Override
    public void onSendKey(String uid, String toUid,String lockId,String send_type,  String start,
                        String end, String mark) {
        // TODO Auto-generated method stub
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("to_mobile", toUid);//
            map.put("lock_id", lockId);//
            map.put("send_type", send_type);//钥匙类型8.0 说明里面的钥匙类型 管理员发送(1用户/2租户),租户发送(3租户用户)]
            map.put("start", start);//
            map.put("end", end);
            map.put("mark", mark);
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(sendKey, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("to_mobile", toUid);//
            map.put("lock_id", lockId);//
            map.put("send_type", send_type);//钥匙类型8.0 说明里面的钥匙类型 管理员发送(1用户/2租户),租户发送(3租户用户)]
            map.put("start", start);//
            map.put("end", end);
            map.put("mark", mark);
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(sendKey, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }
    /**
     * 锁的钥匙列表
     */
    @Override
    public void onKeyOfLock(String uid, String lockId) {
        // TODO Auto-generated method stub

        Type type = new TypeToken<AdminKeyBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lockId);
            (new ByJsonRequest.Builder<AdminKeyBean>(lock))
                    .setTypeVerParamsAndReturnClass(keyOfLock, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<AdminKeyBean>(
                                    getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lockId);
            (new ByJsonRequest.Builder<AdminKeyBean>())
                    .setTypeVerParamsAndReturnClass(keyOfLock, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<AdminKeyBean>(
                                    getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }
    /**
     * 键盘密码记录
     */
    @Override
    public void onPassJiLu(String uid, String lock_id, String current_page, String per_page) {
        Type type = new TypeToken<GuanLiPassBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lock_id);
            map.put("current_page", current_page);
            map.put("per_page", per_page);
            (new ByJsonRequest.Builder<GuanLiPassBean>(lock))
                    .setTypeVerParamsAndReturnClass(passJiLu, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<GuanLiPassBean>(
                                    getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lock_id);
            map.put("current_page", current_page);
            map.put("per_page", per_page);
            (new ByJsonRequest.Builder<GuanLiPassBean>())
                    .setTypeVerParamsAndReturnClass(passJiLu, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<GuanLiPassBean>(
                                    getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }
    /**
     * 解绑管理员
     */
    @Override
    public void onUnbindLock(String uid, String lockId, String key_id,String auth_out) {
        // TODO Auto-generated method stub
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lockId);
            map.put("key_id", key_id);
            map.put("auth_out", auth_out);
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(unbindAdmin, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lockId);
            map.put("key_id", key_id);
            map.put("auth_out", auth_out);
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(unbindAdmin, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }

    /**
     * 是否开启推送
     * @param push  [0(d)=>不推送，1=>推送]
     */
    @Override
    public void onTuiSong(String uid, String lock_id, int push) {
        // TODO Auto-generated method stub
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("lock_id", lock_id);
        map.put("push", push);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(tuisong, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 密码添加前置
     */
    @Override
    public void onQianZhi(String uid, String lock_id) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("lock_id", lock_id);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(qianzhi, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 密码删除回调
     */
    @Override
    public void onDeletePass(String uid, String lock_id, String keyboard_id) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("lock_id", lock_id);
        map.put("keyboard_id", keyboard_id);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(deletePass, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 密码修改回调
     * @param uid
     * @param lock_id
     * @param keyboard_id   ,密码位id
     * @param pwd           密码值
     * @param start
     * @param end
     */
    @Override
    public void onModifyPass(String uid, String lock_id, String keyboard_id, String pwd, String start, String end) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("lock_id", lock_id);
        map.put("keyboard_id", keyboard_id);
        map.put("pwd", pwd);
        map.put("start", start);
        map.put("end", end);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(modifyPass, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onAddPass(String uid,String lock_id,String pwd_list,String app_time,String start,String end,String pwd) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("lock_id", lock_id);
            map.put("pwd_list", pwd_list);
            map.put("app_time", app_time);
            map.put("start", start);
            map.put("end", end);
            map.put("pwd", pwd);
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(addPass, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("lock_id", lock_id);
            map.put("pwd_list", pwd_list);
            map.put("app_time", app_time);
            map.put("start", start);
            map.put("end", end);
            map.put("pwd", pwd);
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(addPass, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }

    @Override
    public void onModifyAlias(String uid, String lock_id, String keyboard_id, String alias) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("lock_id", lock_id);
        map.put("keyboard_id", keyboard_id);
        map.put("alias", alias);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(modifyAlias, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onEditkey(String uid, String key_id, String mark) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        boolean lock= (boolean) SPUtils.get(MyApplcation.ctx,null, SPContants.ISLOCK,false);
        if (lock){
            map.put("sid", uid);
            map.put("key_id", key_id);
            map.put("mark", mark);
            (new ByJsonRequest.Builder<String>(lock))
                    .setTypeVerParamsAndReturnClass(bieming, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener(),lock))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }else {
            map.put("uid", uid);
            map.put("key_id", key_id);
            map.put("mark", mark);
            (new ByJsonRequest.Builder<String>())
                    .setTypeVerParamsAndReturnClass(bieming, apiVer, map, type)
                    .requestListener(
                            new BaseSuccessReqListener<String>(getListener()))
                    .errorListener(new BaseErrorListener(getListener()))
                    .desEncodeThenBuildAndSend();
        }

    }

}
